<%--
  Created by IntelliJ IDEA.
  User: 60567
  Date: 2019/2/21
  Time: 20:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="com.ewentsai.*" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
    ArrayList<Article> articles = new ArrayList<>();
    Connection connection = DB.getConnection();
    Statement statement = DB.createStatement(connection);
    ResultSet rSet = DB.executeQuery(statement, "select * from article");
    int articleSize = 0;
    while (rSet.next()){
        articleSize++;
        Article article = new Article();
        article.getInitFormRS(rSet);
        if(article.getPid()==0){
            articles.add(article);
        }
    }
    articleSize++;
%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>L2C</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .header{
            height: 10%;
            background-color: black;
        }
        .main{
            height: 100%;
            width: 100%;
            background-color: darkgrey;
        }
        .post-title{
            height: 3%;
            width: 100%;
            background-color: darkgrey;
        }
        .post-time{
            height: 3%;
            width: 10%;
            float: right;
            background-color: darkgrey;
        }
        .main-left{
            height: 100%;
            width: 20%;
            background-color: slategray;
            float: left;
        }
        .header-button{
            width: 40%;
            height: 50px;
            margin: 0 auto;
            float: right;
        }
        .toolbar-style{
            height: 3%;
            background-color: beige;
        }
        .button-style{
            display: inline-block;
            border-radius: 4px;
            background-color: darkgrey;
            border: none;
            color: #FFFFFF;
            text-align: center;
            font-size: 16px;
            padding: 15px;
            width: 10%;
            transition: all 0.5s;
            cursor: pointer;
            margin: 3%;
        }
    </style>
</head>
<%
    String loginUserName;
    loginUserName = request.getParameter("loginUserName");
    if(loginUserName==null){
        loginUserName = "登录";
    }
%>
<body>
<div class="header">
    <font size="22" color="white">Blog</font>
    <header class="header-button">
        <a href="login.jsp"><button class="button-style"><span><%= loginUserName%></span></button></a>
        <a href="RegisterPage.jsp"><button class="button-style"><span>注册</span></button></a>
    </header>
</div>
<div class="toolbar-style">
    <div><a href="DevelopingPage.html">电子书商城</a> </div>
</div>
<div>
    <div style="height: 69px;background-color: cornflowerblue">
        <a href="reply.jsp?loginUserName=<%= loginUserName %>&pid=<%= 0%>&size=<%= articleSize%>">发布新主题</a>
    </div>
</div>
<div class="main">
    <div class="main-left"></div>
    帖子列表<br>
    <%
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        for(int i=0; i<articles.size(); i++){
            Article article = articles.get(i);
    %>
    <div class="post-title">
        <a href="ArticlePage.jsp?id=<%= article.getId() %>&loginUserName=<%= loginUserName %>">
            <% out.print(article.getTitle()); %>
        </a>
        <div class="post-time">
            <%= ft.format(article.getCreateTime()) %>
        </div>
    </div>
    <hr>
    <%
        }
    %>
</div>
</body>
</html>